//javascript:

var doc=document;
if(window.frames.length>0)
	doc=window.main.document;
var tds=doc.getElementsByTagName("TD");
var K=new Array();
for(var idx=0;idx<100;idx++)K[idx]=new Array();
var C=new Array();for(var idx=0;idx<tds.length;idx++){
	var xy=tds[idx].innerHTML;
	if(/^\d+\|\d+$/.test(xy)){
		C.push(xy);
		var xys=xy.split('|');
		K[Math.floor(parseInt(xys[0])/100)+Math.floor(parseInt(xys[1])/100)*10].push(xy);
	}
}
C=C.join(' ');
var prefix='<textarea cols=80 rows=10>[u][b][size=12]Nuking:Random coords[/size][/b][/u]\n\n[spoiler]javascript:coords=\'';
var postfix='\';var doc=document;if(window.frames.length>0)doc=window.main.document;coords=coords.split(\' \');index=Math.round(Math.random()*(coords.length-1));coords=coords[index];coords=coords.split(\'|\');doc.forms[0].x.value=coords[0];doc.forms[0].y.value=coords[1];selectAllUnits(true);end();[/spoiler] </textarea><br><br>';
var S='<b>=RedFox= Random Nukes</b><hr>All Villages:<br>'+prefix+C+postfix;
for(var idx=0;idx<100;idx++)if(K[idx].length>0){
	var Ks=K[idx].join(' ');
	S+='<br><br>K'+idx+' Villages:<br>'+prefix+Ks+postfix;
}
var outputWin=window.open();
outputWin.document.open('text/html','replace');
outputWin.document.write(S);
outputWin.document.close();
void 0;
var prefix='<textarea cols=80 rows=10>[u][b][size=12]Sequential Nukes; In order[/size][/b][/u]\n\n[spoiler][code]javascript:function z(){t=\'';
var postfix='\';var d=(window.frames.length>0)?window.main.document:document;if(d.URL.indexOf(\'screen=place\')==-1){alert(\'Not on Rally Point :(\');return;}t=t.split(" ");i=0;f=d.cookie.match(\'(^|;) ?farm=([^;]*)(;|$)\');if(f!=null)i=parseInt(f[2]);n=t.length;if(i==(n-1))alert(\'last village : \'+n+" of "+n);if(i>=n)i=0;if(i==0)alert(\'first village : 01 of \'+n);t=t[i];t=t.split("|");q=new Date(2099,11,11);d.cookie="farm="+(i+1)+";expires="+q.toGMTString();f=d.forms[0];f.x.value=t[0];f.y.value=t[1];selectAllUnits(true);}z();[/code][/spoiler] </textarea><br><br>';
var S='<b>=RedFox= Nuke in Order</b><hr>All Villages:<br>'+prefix+C+postfix;
for(var idx=0;idx<100;idx++)
	if(K[idx].length>0){var Ks=K[idx].join(' ');
	S+='<br><br>K'+idx+' Villages:<br>'+prefix+Ks+postfix;
}
var outputWin=window.open();
outputWin.document.open('text/html','replace');
outputWin.document.write(S);
outputWin.document.close();
void 0;
var prefix='<textarea cols=80 rows=10>[b][u][size=12]Random Coords: 1 ram[/size][/u][/b]\n\n[spoiler]javascript:coords=\'';
var postfix='\';var doc=document;if(window.frames.length>0)doc=window.main.document;coords=coords.split(\' \');index=Math.round(Math.random()*(coords.length-1));coords=coords[index];coords=coords.split(\'|\');doc.forms[0].x.value=coords[0];doc.forms[0].y.value=coords[1];insertUnit(doc.forms[0].ram,1);end();[/spoiler] </textarea><br><br>';var S='<b>=RedFox= Random 1 Ram</b><hr>All Villages:<br>'+prefix+C+postfix;
for(var idx=0;idx<100;idx++)
	if(K[idx].length>0){
		var Ks=K[idx].join(' ');
		S+='<br><br>K'+idx+' Villages:<br>'+prefix+Ks+postfix;
	}
var outputWin=window.open();
outputWin.document.open('text/html','replace');
outputWin.document.write(S);
outputWin.document.close();
void 0;
var prefix='<textarea cols=80 rows=10>[b][u][size=12]Random Coords: 1 scout + 1 ram or cat[/size][/u][/b]\n\n[spoiler]javascript:coords=\'';
var postfix='\';var eleDoc=(window.frames.length>0)?window.main.document:document;function fnFillRallyPoint(){var coord=coords.split(\' \');var coordSplit=coord[Math.round(Math.random()*(coord.length-1))].split(\'|\');eleDoc.forms[0].x.value=coordSplit[0];eleDoc.forms[0].y.value=coordSplit[1];var scouts=parseInt(eleDoc.forms[0].spy.nextSibling.nextSibling.innerHTML.match(/\\d+/));if(scouts>0){eleDoc.forms[0].spy.value=1;}rams=parseInt(eleDoc.forms[0].ram.nextSibling.nextSibling.innerHTML.match(/\\d+/));if(rams>0){eleDoc.forms[0].ram.value=1;}else{eleDoc.forms[0].catapult.value=1;}}fnFillRallyPoint();[/spoiler] </textarea><br><br>';
var S='<b>=RedFox= Random 1 Scout & 1 Ram or Cat</b><hr>All Villages:<br>'+prefix+C+postfix;
for(var idx=0;idx<100;idx++)
	if(K[idx].length>0){
		var Ks=K[idx].join(' ');
		S+='<br><br>K'+idx+' Villages:<br>'+prefix+Ks+postfix;
	}
var outputWin=window.open();outputWin.document.open('text/html','replace');
outputWin.document.write(S);outputWin.document.close();
void 0;

//javascript:
var doc=document;
if(window.frames.length>0){
	doc=window.main.document;
}
var tds=doc.getElementsByTagName("TD");
var K=new Array;
for(var idx=0;idx<100;idx++){
	K[idx]=new Array;
}
var C=new Array;
for(var idx=0;idx<tds.length;idx++){
	var xy=tds[idx].innerHTML;
	if(/^\d+\|\d+$/.test(xy)){
		C.push(xy);
		var xys=xy.split("|");
		K[Math.floor(parseInt(xys[0])/100)+Math.floor(parseInt(xys[1])/100)*10].push(xy);
	}
}
C=C.join(" ");
var prefix="<textarea cols=80 rows=10>[u][b][size=12]Sequential Fake, Fakes in order: Enter the amount of units you wish to fake with in the beginning of the script.[/size][/b][/u]\n\n[spoiler]javascript:function end(){var sp=0,sw=0,ax=0,ar=0,scout=0,lc=0,mount=0,hv=0,cat=0,ra=0,pa=0,no=0;coords='";var postfix='\';var doc=document;if(window.frames.length>0)doc=window.main.document;coords=coords.split(\'%20\');index=0;farmcookie=document.cookie.match(\'(^|;) ?farm=([^;]*)(;|$)\');if(farmcookie!=null)index=parseInt(farmcookie[2]);if(index>=coords.length)alert(\'last village\');if(index>=coords.length)index=0;coords=coords[index];coords=coords.split(\'|\');index=index+1;cookie_date=new Date(2099,11,11);document.cookie =\'farm=\'+index+\';expires=\'+cookie_date.toGMTString ();doc.forms[0].x.value=coords[0];doc.forms[0].y.value=coords[1];doc.forms[0].spear.value=sp;doc.forms[0].sword.value=sw;doc.forms[0].axe.value=ax;doc.forms[0].spy.value=scout;doc.forms[0].light.value=lc;doc.forms[0].heavy.value=hv;doc.forms[0].ram.value=ra;doc.forms[0].catapult.value=cat;doc.forms[0].archer.value=ar;doc.forms[0].marcher.value=mount;doc.forms[0].knight.value=pa;doc.forms[0].snob.value=no;}end();[/spoiler] </textarea><br><br>';var S="<b>=RedFox= Fake in Order: Enter Desired Unit Amount in the Beginning of Script</b><hr>All Villages:<br>"+prefix+C+postfix;
for(var idx=0;idx<100;idx++){
	if(K[idx].length>0){
		var Ks=K[idx].join(" ");
		S+="<br><br>K"+idx+" Villages:<br>"+prefix+Ks+postfix;
	}
}
var outputWin=window.open();
outputWin.document.open('text/html','replace');
outputWin.document.write(S);
outputWin.document.close();
void 0;

var prefix="<textarea%20cols=80%20rows=10>[b][u][size=12]Fake Train: 4 rams[/size][/u][/b]\n\n[spoiler]javascript:coords='";
var postfix='\';var doc=document;if(window.frames.length>0)doc=window.main.document;url=document.URL;if(url.indexOf(\'screen=place\')==-1)alert(\'This script%20needs to be run from the rally point\');coords=coords.split(" ");index=Math.round(Math.random()*(coords.length-1));counter=1;cookienoble=document.cookie.match(\'(^|;) ?noblefake=([^;]*)(;|$)\');cookiecounter=document.cookie.match(\'(^|;) ?noblecounter=([^;]*)(;|$)\');if(cookienoble!=null)index=parseInt(cookienoble[2]);if(cookiecounter!=null)counter=parseInt(cookiecounter[2]);if(counter==5)index=Math.round(Math.random()*(coords.length-1));if(counter==5)counter=1;coords=coords[index];coords=coords.split("|");counter=counter+1;cookie_date=new Date(2019,11,11);document.cookie="noblefake="+index+";expires="+cookie_date.toGMTString ();document.cookie ="noblecounter="+counter+";expires="+cookie_date.toGMTString ();doc.forms[0].x.value=coords[0];doc.forms[0].y.value=coords[1];javascript:function i(){function j(b){function k(c,f,g){if(f==0){return 1;}if(g==0){return 0;}if(f<0){f=g+f;}if(f<=0){return 0;}if(f<=g){c.value=f;return 1;}else{c.value=g;return 0;}}var d=document,g,c,e,l=1;if(window.frames.length>0)d=window.main.document;var a=d.units.getElementsByTagName(\'input\');for(var h=0;h<(a.length-4)&&h<b.length;h++){if(b[h]!=null&&b[h]!=0){e=a[h].nextSibling;do{e=e.nextSibling;}while(e.nodeType!=1);g=parseInt(e.firstChild.nodeValue.match(/(\\d+)/)[1],10);l=l&&k(a[h],b[h],g);}}return%20l;}if(!j([,,,,,,1])){j([,,,,,,,1]);}}i();end();[/spoiler] </textarea><br><br>';
var S="<b>=RedFox= Fake Train: 4 Rams</b><hr>All Villages:<br>"+prefix+C+postfix;
for(var idx=0;idx<100;idx++){
	if(K[idx].length>0){
		var Ks=K[idx].join(" ");
		S+="<br><br>K"+idx+" Villages:<br>"+prefix+Ks+postfix;
	}
}
var outputWin=window.open();
outputWin.document.open('text/html','replace');
outputWin.document.write(S);
outputWin.document.close();
void 0;

var prefix="<textarea cols=80 rows=10>[b][u][size=12]Fake Train: 5 rams[/size][/u][/b]\n\n[spoiler]javascript:coords='";
var postfix='\';var doc=document;if(window.frames.length>0)doc=window.main.document;url=document.URL;if(url.indexOf(\'screen=place\')==-1)alert(\'This script%20needs to be run from the rally point\');coords=coords.split(" ");index=Math.round(Math.random()*(coords.length-1));counter=1;cookienoble=document.cookie.match(\'(^|;) ?noblefake=([^;]*)(;|$)\');cookiecounter=document.cookie.match(\'(^|;) ?noblecounter=([^;]*)(;|$)\');if(cookienoble!=null)index=parseInt(cookienoble[2]);if(cookiecounter!=null)counter=parseInt(cookiecounter[2]);if(counter==6)index=Math.round(Math.random()*(coords.length-1));if(counter==6)counter=1;coords=coords[index];coords=coords.split("|");counter=counter+1;cookie_date=new Date(2019,11,11);document.cookie="noblefake="+index+";expires="+cookie_date.toGMTString ();document.cookie ="noblecounter="+counter+";expires="+cookie_date.toGMTString ();doc.forms[0].x.value=coords[0];doc.forms[0].y.value=coords[1];javascript:function i(){function j(b){function k(c,f,g){if(f==0){return 1;}if(g==0){return 0;}if(f<0){f=g+f;}if(f<=0){return 0;}if(f<=g){c.value=f;return 1;}else{c.value=g;return 0;}}var d=document,g,c,e,l=1;if(window.frames.length>0)d=window.main.document;var a=d.units.getElementsByTagName(\'input\');for(var h=0;h<(a.length-4)&&h<b.length;h++){if(b[h]!=null&&b[h]!=0){e=a[h].nextSibling;do{e=e.nextSibling;}while(e.nodeType!=1);g=parseInt(e.firstChild.nodeValue.match(/(\\d+)/)[1],10);l=l&&k(a[h],b[h],g);}}return%20l;}if(!j([,,,,,,1])){j([,,,,,,,1]);}}i();end();[/spoiler] </textarea><br><br>';var S="<b>=RedFox= Fake Train: 5 rams</b><hr>All Villages:<br>"+prefix+C+postfix;
for(var idx=0;idx<100;idx++){
	if(K[idx].length>0){
		var Ks=K[idx].join(" ");S+="<br><br>K"+idx+" Villages:<br>"+prefix+Ks+postfix;
	}
}
var outputWin=window.open();
outputWin.document.open('text/html','replace');
outputWin.document.write(S);
outputWin.document.close();
void 0;

//javascript:
if(window.location.href.match(/screen\=info_player/i)){
	function zeroPad(number,length){
		var n=number.toString();
		while(n.length<length){
			n="0"+n;
		}
		return n;
	}
	var player=$("#content_value table[class*=vis] th:first").text();
	var tribe=$("#content_value table[class*=vis] a:first").text();
	var village=[];
	var villages=new Array(100);
	$("#content_value tr:has(th:contains('Coordinates')):last~tr td")
		.each(function(i,e){
			village[i%253]=(e.textContent||e.innerText);
			if((i>0)&&(i%253==2)){
				var coord=village[1].split("|");
				coord[0]=zeroPad(coord[0],3);
				coord[1]=zeroPad(coord[1],3);
				var k=parseInt(coord[1][0]+coord[0][0],10);
				if(typeof(villages[k])=="undefined"){
					villages[k]=[];
				}
				villages[k].push(village);
				village=[];
			}
		});
	var output="";
	var ii,jj,index=1;
	for(ii=0;ii<100;ii++){
		if((typeof(villages[ii])!="undefined")&&(villages[ii].length>0)){
			output+="K"+zeroPad(ii,2)+" - "+villages[ii].length+" villages;\n";
			for(jj=0;jj<villages[ii].length;jj++){
				output+=zeroPad(index++,4) + " - [coord]"+villages[ii][jj][1]+"[/coord] - "+villages[ii][jj][2]+" ==> \n";
			}
			output+="\n\n";
		}
	}
	function winWrite(title,str){
		return outputWin.document.write("<h3>"+ title +":</h3><textarea cols='80' rows='40' onFocus='this.select()'>"+str+"</textarea><br/>");
	}
	var outputWin=window.open();
	winWrite("=RedFox= Uber Op Planner","Player: [player]"+player+"[/player]\nTribe: [ally]"+tribe+"[/ally]\n\n\n"+output);
	outputWin.document.close();
}
void(0);

